<%@ include file="/common/taglibs.jsp"%>
<%@ page import="idv.takeshi.software.productline.bookstore.domain.model.order.Order" %>
<%@ page import="idv.takeshi.software.productline.bookstore.domain.model.order.BeforeDeliveryPayment" %>
<%@ page import="idv.takeshi.software.productline.bookstore.domain.model.order.CreditCard" %>
<%@ page import="idv.takeshi.software.productline.bookstore.domain.model.order.AfterDeliveryPayment" %>

<c:set var="goToPayByCreditCardUrl"><spring:url value="/payment/payByCreditCard.html">
	<spring:param name="orderId" value="${order.id}"/>
	<spring:param name="previousPath" value="${previousPath}"/>
</spring:url></c:set>

<c:set var="goToSeeOrderDetailsInfoUrl"><spring:url value="/order/orderInfo.html">
	<spring:param name="seeOrderDetailsInfo">true</spring:param>
	<spring:param name="previousPath" value="${previousPath}"/>
</spring:url></c:set>

<head>
	<title><spring:message code="paymentNotice.header"/></title>
	<script type="text/javascript">
	$(document).ready(function(){
		$("#payByCreditCard").click(function(){
			location.assign("${goToPayByCreditCardUrl}");
		});

		$("#orderInfo").click(function(){
			location.assign("${goToSeeOrderDetailsInfoUrl}");
		});

	});
	</script>
</head>

<div class="ui-widget summary-booklist">
	<h1 class="ui-helper-reset ui-widget-header ui-corner-top booklist-header">
		<spring:message code="paymentNotice.header"/>
	</h1>
	<div class="ui-widget-content ui-corner-bottom" style="text-align: center;">
	<c:choose>
		<c:when test="${order.payment.paid == true}">
		<spring:message code="paymentNotice.payment.paid.description"/>
		</c:when>
		<c:otherwise>	
		<%
		Order order = null;
		order = (Order)request.getAttribute("order");
		if(order.getPayment() instanceof AfterDeliveryPayment){
		%>
		<spring:message code="paymentNotice.afterDeliveryPayment.description"/>
		
		<%
		} else if(order.getPayment() instanceof CreditCard){
		%>
			<spring:message code="paymentNotice.creditCard.description"/><br/>
			<button id="payByCreditCard" class="aButton"><spring:message code="paymentNotice.creditCard.pay"/></button>
		<%
		} else{
		%>
		<c:set var="paymentName"><spring:message code="${sf:getPaymentMessageCode(order.payment)}"/></c:set>
		<spring:message code="paymentNotice.beforeDeliveryPayment.description" 
			arguments="${paymentName}"/>
		<%
		}
		%>
		</c:otherwise>
	</c:choose>
	<p></p>
	<button id="orderInfo" class="aButton"><spring:message code="paymentNotice.orderInfo"/></button>
	</div>
</div>